package com.atguigu.gmall.logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author: Felix
 * Date: 2022/4/18
 * Desc: 日志采集服务---接收前端埋点产生的日志数据  并对其进行处理
 * 打印到控制台
 * 落盘
 * 发送到kafka主题
 */
@RestController
@Slf4j
public class LoggerController {

    //private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerController.class);

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String logStr) {
        //打印到控制台 、落盘    借助于第三方记录日志的组件 logback
        log.info(logStr);

        //发送到kafka主题
        kafkaTemplate.send("ods_base_log",logStr);

        return "success";
    }

}
